<template>
	<view>
		<view style="display: flex;margin-bottom: 20rpx;">
			<view class="selected_box">
				<view style="text-indent: 1em;"> <text></text>{{lableName}}: </view>
				<view @click="$emit('change',item[keyName],false)" v-for="(item,index) in selectData"
					class="selected_box_item">{{item[keyName]}}
				</view>
			</view>
		</view>
		<view class="selected_box">
			<view style="text-indent: 1em;"> <text></text>常用{{lableName}}: </view>
			<view class="not_selected_item" @click="$emit('change',item[keyName],true)"
				v-for="(item,index) in unSelectData">{{item[keyName]}}
			</view>
		</view>
		<view style="display: flex;gap: 20rpx;margin-top: 20rpx;align-items: center;">
			<text>自定义{{lableName}}:</text>
			<view class="input">
				<input v-model="name" type="text" style="flex: 1;" :placeholder="`请输入${lableName}`">
			</view>
			<u-button @click="$emit('add',name)" :custom-style="addBtn"  shape="circle" text="添加"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		/**
		 * @property {any} type 0为颜色 1为尺寸
		 */
		props: ["data", "type"],
		data(){
			return{
				addBtn:{
					textIndent: 0,
					padding: "20rpx",
					backgroundColor: "red",
					color: "#fff",
					width: "auto",
					height: "auto",
					boxSizing: "border-box"
				},
				name:''
			}
		},
		
		
		computed: {
			selectData(){
				console.log(this.data);
				return this.data.filter(item=>item.select)
			},
			unSelectData(){
				return this.data.filter(item=>!item.select)
			},
			lableName() {
				if(this.type == 0){
					return "颜色"
				}
				if(this.type == 1){
					return "尺寸"
				}
			},
			keyName(){
				if(this.type == 0){
					return "colName"
				}
				if(this.type == 1){
					return "sizeName"
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.input {
		display: flex;
		align-items: center;
		color: #000;
		flex: 1;
	
		input {
			height: 94rpx;
			background: #f2f2f2;
			border-radius: 47rpx;
			width: 100%;
		}
	}
	.selected_box {
		flex: 1;
		align-items: center;
		display: flex;
		text-indent: 0;
		gap: 20rpx;
		flex-wrap: wrap;
	
		.selected_box_item {
			background-color: red;
			color: #fff;
	
			padding: 10rpx;
		}
	
		.not_selected_item {
			color: black;
			background-color: #f2f2f2;
			text-indent: 0;
			padding: 10rpx;
		}
	}
	.addBtn {
		
	}
</style>